<script lang="ts" setup>
import { CouponApi } from '@/apis'

defineProps<{
  modelValue: string | number
}>()
const couponList = ref<CouponApi.CouponTemplateResp[]>()
const couponLoading = ref<boolean>(false)
const model = defineModel<string | number>()

const getCouponTemplateList = async (name: string = '') => {
  try {
    couponLoading.value = true
    const res = await CouponApi.getCouponTemplatePage({
      name,
      status: 1,
      page: 1,
      size: 30,
    })
    couponList.value = res.records || []
  } finally {
    couponLoading.value = false
  }
}

onMounted(() => {
  getCouponTemplateList()
})
</script>

<template>
  <a-select
    v-model="model" placeholder="请选择优惠券（输入关键字搜索）" :options="couponList" :loading="couponLoading"
    allow-search :filter-option="false" :show-extra-options="false" :field-names="{ label: 'name', value: 'id' }" @search="getCouponTemplateList"
  />
</template>

<style lang='less' scoped>
</style>
